package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/3/1.
 */
public class LC279 {

    public int numSquares(int n) {
        int[] dp = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            dp[i] = i;//assume worse condition
            for (int j = 0; i - j * j >= 0; j++) {
                dp[i] = Math.min(dp[i], dp[i - j * j] + 1);
            }
        }

        return dp[n];
    }


    public static void main(String[] args) {
        LC279 an = new LC279();
        System.out.println(an.numSquares(13));
    }
}
